using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Golem : EnemyController
{
    [Header("Skill")]
    public float kickForce = 35;
    public GameObject rockPrefab;
    public Transform handPos;
    // Animation Event
    public void KickOff()
    {
        if (attackTarget != null && transform.IsFacingTarget(attackTarget.transform))
        {
            var targetStat = attackTarget.GetComponent<CharacterStats>();
            // 拿到被攻击目标的 agent 给一个线速度模拟击飞效果

            Vector3 direction = (attackTarget.transform.position - transform.position).normalized;

            NavMeshAgent agent = attackTarget.GetComponent<NavMeshAgent>();

            agent.isStopped = true;

            agent.velocity = kickForce * direction;
            // 击飞时眩晕玩家
            targetStat.GetComponent<Animator>().SetTrigger("Dizzy");

            targetStat.TakeDamage(enemyStat, targetStat);
        }
    }
    // Animation Event
    public void ThrowRock()
    {
        if (attackTarget != null)
        {
            var rock = Instantiate(rockPrefab, handPos.position, Quaternion.identity);
            // 记录攻击目标
            rock.GetComponent<Rock>().target = attackTarget;
        }
    }
}
